-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New process to upload a broadcast replay to IGTV #1364
base: master
Are you sure you want to change the base?
Conversation
let data = await ig.live.getPostLiveThumbnails(broadcast_id) | ||
|
||
// Download any thumb | ||
let file = await new Promise((resolve) => https.get(data.thumbnails[0], (download) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you could use request-promise
as it's already a dependency of this library.
let igtv = null | ||
let currentRetry = 0 | ||
let maxRetry = 3 | ||
let retryDelay = 4 | ||
while (!igtv) { | ||
// This endpoint can return an error "202 Accepted; Transcode not finished yet" if Instagram has not finished to process the previous upload, so retry later in this case | ||
try { | ||
igtv = await ig.media.configureToIgtv({ | ||
upload_id: upload.upload_id, | ||
title: 'A title', | ||
caption: 'A description', | ||
igtv_share_preview_to_feed: '1', | ||
}) | ||
|
||
console.log(`Live posted to IGTV : ${igtv.upload_id}`)) | ||
} catch (e) { | ||
currentRetry++ | ||
if (currentRetry > maxRetry) { | ||
throw e | ||
} else { | ||
await (new Promise(resolve => { | ||
setTimeout(resolve, currentRetry * retryDelay) | ||
})) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could live in its own function and not pollute the current function.
For example:
async function retryDelayed<T>(fn: () => Promise<T>, retryOptions: { retries: number, delayMs: number }): Promise<T> {
let step = 0;
while(step++ < retryOptions.retries) {
try {
return await fn();
} catch(e) {
if(step >= retryOptions.retries) throw e;
await new Promise(r => setTimeout(r, step * retryOptions.delayMs));
}
}
}
// used like this:
const user = await retryDelayed(() => ig.user.info(123), {retries: 2, delayMs: 2 * 1000 /* 2s */ });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tips @Nerixyz .
But before doing this... I really can't understand, it's not working anymore. I made and tested this PR yesterday, and today, I got a 500 error with the endpoint "/api/v1/media/configure_to_igtv/".
I think that there is a problem with my picture upload because if I use in the configureToIgtv method an existing "upload_id" (that I get from the app directly, so i'm bypassing the "download, convert and upload thumb for broadcast" step), it works.
If you have any idea... You're welcome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content/site-policy/content-removal-policies/github-private-information-removal-policy.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tips @Nerixyz .
But before doing this... I really can't understand, it's not working anymore. I made and tested this PR yesterday, and today, I got a 500 error with the endpoint "/api/v1/media/configure_to_igtv/".
I think that there is a problem with my picture upload because if I use in the configureToIgtv method an existing "upload_id" (that I get from the app directly, so i'm bypassing the "download, convert and upload thumb for broadcast" step), it works.
If you have any idea... You're welcome!
fb238a8
to
774885a
Compare
I moved the retry step in case of a "202 Accepted; Transcode not finished yet" to the repository with an optional parameter on the configureToIgtv method to set the retry delay. I didn't found why certain of my broadcast can't be uploaded as an IGTV and still get an 500 error... My update works with new broadcasts. |
774885a
to
671f8da
Compare
It's probably still the best to stick to request. We know request is deprecated now and probably the best alternative would be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this may introduce an infinite loop as Instagram may always send 202
. But I don't think they'd do this; after a while we'd probably get a spam-error or 500
.
src/repositories/media.repository.ts
Outdated
}); | ||
|
||
let body = null; | ||
let response = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable doesn't need to be here. It can live in the while
body.
Yes I know, but I took the liberty of choosing an other HTTP client because it's just an example file and not part of the library. |
785ccb5
to
351a3a8
Compare
351a3a8
to
2fedb9a
Compare
Updated to use the publish service |
Hello guys |
Is this PR going to be merged? I believe this issue still persists. |
|
The broadcast replay to IGTV has changed in the app, the endpoint "/api/v1/live/add_post_live_to_igtv/" no longer exists
#1304